/**
 * Created by dukes on 2015/12/4.
 */
class MyChatItem extends eui.Component{
    private data:any;
    public constructor(){
        super();
        this.skinName = "pet.MyChatItemSkin";
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAdded, this);
    }

    private onAdded(evt:egret.Event){
        if( this.data){
            this.setData(this.data);
        }
    }

    public setData(data:any){
        if( !this.parent){
            this.data = data;
            return;
        }

        this.message.text = data.message;
    }

    private message:eui.Label;
    private img_head:eui.Image;
    public partAdded(name:string, instance:any){
        super.partAdded(name, instance);
        if( name == "message"){
            this.message = instance;
        }else if( name == "img_head"){
            this.img_head = instance;
            if( Model.me.platform != PlatformEnum.QQBROWSER){
                this.img_head.source = Model.me.platform != PlatformEnum.QQBROWSER ? Model.me.figureurl : RES.getRes("default_head_0");
            }else{
                this.img_head.source = RES.getRes("default_head_"+(Model.me.id%5));
            }
        }
    }
}